------------------ fgui require start ------------------
local GuildAddresSelectSkin = require 'View/UIGuild/Skin/GuildAddresSelectSkin';
local Btn_guildnamemodificationSkin = require 'View/UIGuild/Skin/Btn_guildnamemodificationSkin';
local GuildNameModifySkin = require 'View/UIGuild/Skin/GuildNameModifySkin';
------------------  fgui require end  ------------------
local GuildInfoSettingSkin = Class("GuildInfoSettingSkin");
require "proto/union/bean/UnionSettingInfo"

function GuildInfoSettingSkin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.ctl_choice.onChanged:Add(self.onChange_Ctl_choice,self);
    self.ctl_showModifyName.onChanged:Add(self.onChange_Ctl_showModifyName,self);
    self.btn_blackbackground.onClick:Add(self.onTouch_Btn_blackbackground,self);
    self.btn_replace.onClick:Add(self.onTouch_Btn_replace,self);
    self.btn_choice.onClick:Add(self.onTouch_Btn_choice,self);
    self.btn_choice1.onClick:Add(self.onTouch_Btn_choice1,self);
    self.btn_finish.onClick:Add(self.onTouch_Btn_finish,self);
    self.btn_modifyName.onClick:Add(self.onTouch_Btn_modifyName,self);
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function GuildInfoSettingSkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.ctl_choice = com:GetController("Ctl_choice");
    self.ctl_showModifyName = com:GetController("Ctl_showModifyName");
    self.btn_blackbackground = com:GetChild("Btn_blackbackground");
    self.btn_replace = com:GetChild("Btn_replace");
    self.btn_choice = com:GetChild("Btn_choice");
    self.btn_choice1 = com:GetChild("Btn_choice1");
    self.com_address = GuildAddresSelectSkin.New(com:GetChild("Com_address"));
    self.btn_finish = com:GetChild("Btn_finish");
    self.btn_modifyName = com:GetChild("Btn_modifyName");
    self.com_modifyName = GuildNameModifySkin.New(com:GetChild("Com_modifyName"));
    self.text_amendmentnotice = com:GetChild("Text_amendmentnotice");
    self.text_close = com:GetChild("Text_close");
    self.text_guildName = com:GetChild("text_guildName");
    self.text_location = com:GetChild("Text_location");
    self.text_membershipconditions = com:GetChild("Text_membershipconditions");
    self.text_city = com:GetChild("Text_city");
    self.ldr_flag = com:GetChild("ldr_flag");
    ------------------  fgui变量绑定end  ------------------
end

function GuildInfoSettingSkin:init()
    self.text_amendmentnotice.text = getLanguage("GuildInvestment_1061")
    self.btn_replace.text = getLanguage("GuildInvestment_1042");
    self.btn_choice.text = getLanguage("GuildInvestment_1046");
    self.btn_choice1.text = getLanguage("GuildInvestment_1047");
    self.text_guildName.promptText = getLanguage("GuildInvestment_1043");
    self.text_city.text = getLanguage("GuildInvestment_1036");
    self.text_membershipconditions.text = getLanguage("GuildInvestment_1096");
    self.closeCallback = nil;
    self:updateView();
    ListenEvent(Config.EventType.Union_UpdateSettingInfo_S2C, self.respUnionSetting,self);
end

function GuildInfoSettingSkin:updateView()
    self.flagIdx = logicMgr.GuildManager.getFlagId();
    self.ldr_flag.url = logicMgr.GuildManager.getFlagUrl(self.flagIdx);
    self.text_guildName.text = logicMgr.GuildManager.getUnionName();
    self.ctl_choice.selectedIndex = logicMgr.GuildManager.getUnionSetting().isNeedCheckJoin == 1 and 1 or 0;
    self.com_modifyName:setCloseCallback(function(name) self:hideNameModify(name) end);
    self.com_address:updateView();
end

function GuildInfoSettingSkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.ctl_choice.onChanged:Clear();
    self.ctl_showModifyName.onChanged:Clear();
    self.btn_blackbackground.onClick:Clear();
    self.btn_replace.onClick:Clear();
    self.btn_choice.onClick:Clear();
    self.btn_choice1.onClick:Clear();
    self.com_address:OnDestroy();
    self.btn_finish.onClick:Clear();
    self.btn_modifyName.onClick:Clear();
    self.com_modifyName:OnDestroy();
    ------------------  fgui事件移除end  ------------------
end

function GuildInfoSettingSkin:onChange_choice(event) end

function GuildInfoSettingSkin:onTouch_Btn_blackbackground(obj) 
    if self.closeCallback then self.closeCallback(false) end;
end

function GuildInfoSettingSkin:onTouch_Btn_replace(obj)
    showUI(PanelNames.UIGuildFlag,self.flagIdx,function(flagIdx) 
        self.flagIdx = flagIdx;
        self.ldr_flag.url = logicMgr.GuildManager.getFlagUrl(flagIdx);
    end);
end

function GuildInfoSettingSkin:onTouch_Btn_choice(obj) end

function GuildInfoSettingSkin:onTouch_Btn_choice1(obj) end

function GuildInfoSettingSkin:onTouch_Btn_finish(obj)
    local infoSetting = UnionSettingInfo.New();
    infoSetting.isNeedCheckJoin = self.ctl_choice.selectedIndex;
    infoSetting.province = self.com_address:getProvince();
    infoSetting.city = self.com_address:getCity();
    infoSetting.flagId = self.flagIdx;
    infoSetting.unionNotice = logicMgr.GuildManager.getUnionNotice();
    local unionId = logicMgr.GuildManager.getUnionId();
    unionHandler.reqModifyUnionSetting(unionId,infoSetting);
end

function GuildInfoSettingSkin:onChange_Ctl_showModifyName(event) end

function GuildInfoSettingSkin:onTouch_Btn_modifyName(obj) 
    self.ctl_showModifyName.selectedIndex = 1;
end

function GuildInfoSettingSkin:onChange_Ctl_choice(event) end

------------------  ↑ fgui事件句柄 ↑  ------------------

function GuildInfoSettingSkin:setCloseCallback(func,target)
    self.closeCallback = func;
end

function GuildInfoSettingSkin:hideNameModify(name)
    self.ctl_showModifyName.selectedIndex = 0;
    self.text_guildName.text = logicMgr.GuildManager.getUnionName();
end

function GuildInfoSettingSkin:respUnionSetting()
    if self.closeCallback then self.closeCallback(true) end;
end

function GuildInfoSettingSkin:beforeDestroy() 
    CloseEvent(Config.EventType.Union_UpdateSettingInfo_S2C, self.respUnionSetting,self);
end

return GuildInfoSettingSkin;
